#include "ns3/log.h"
#include "wfq-queue.h"
#include <iostream>

namespace ns3 {

NS_LOG_COMPONENT_DEFINE("WFQQueue");

NS_OBJECT_ENSURE_REGISTERED(WFQQueue);

TypeId WFQQueue::GetTypeId(void) {
  static TypeId tid = TypeId("ns3::WFQQueue")
    .SetParent<Queue>()
    .SetGroupName("Network")
    .AddConstructor<WFQQueue>()
  ;
  return tid;
}

WFQQueue::WFQQueue():
  Queue(),
  m_packets()
{
  NS_LOG_FUNCTION(this);
  m_packets.resize(2);
}

WFQQueue::~WFQQueue() {
  NS_LOG_FUNCTION(this);
}

bool WFQQueue::DoEnqueue(Ptr<QueueItem> item) {
  NS_LOG_FUNCTION(this << item);
  std::cout << "!!!!!!!!!do enqueue here" << std::endl;
  //std::cout << item << std::endl;
  if (item->GetPacket()->GetSize() < 100) {
    m_packets[0].push(item);
  }
  else {
    m_packets[1].push(item);
  }
  return true;
}

Ptr<QueueItem> WFQQueue::DoDequeue(void) {
  NS_LOG_FUNCTION(this);
  // NS_ASSERT(m_packets.size() == GetNPackets());
  //Ptr<QueueItem> item = m_packets.front();
  //m_packets.pop();
  std::cout << "?????????do dequeue here" << std::endl;
  Ptr<QueueItem> item;
  for (int i = 0; i < 2; ++i) {
    if (!m_packets[i].empty()) {
      item = m_packets[i].front();
      m_packets[i].pop();
      break;
    }
  }
  //std::cout << item << std::endl;
  return item;
}

Ptr<const QueueItem> WFQQueue::DoPeek(void) const {
  NS_LOG_FUNCTION(this);
  //NS_ASSERT(m_packets.size() == GetNPackets());
  return m_packets[0].front();
}

} // namespace ns3
